package miagk.elementy;

import java.io.InputStream;

import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.util.BitmapHelper;

import android.content.res.Resources;
import miagk.menu.R;

public class Przewod{

	private Object3D model;
	private int elem1id, elem2id;
	
	public Przewod(SimpleVector pointA, SimpleVector pointB, float width, int id1, int id2){
		model = createLine(pointA, pointB, width);
		elem1id=id1;
		elem2id=id2;
	}
	
	public boolean isCableForElements(int id1, int id2)
	{
		if((elem1id==id1 && elem2id==id2) || (elem1id==id2 && elem2id==id1)) return true;
				return false;
	}
	
	public boolean posiadaPolaczenie(int id)
	{
		if(elem1id==id || elem2id==id) return true;
		return false;
	}
	
	private Object3D createLine (SimpleVector pointA, SimpleVector pointB, float width)
	{
	    Object3D line = new Object3D( 8 );
	    float offset = width / 2.0f;

	    // Quad A:
	    line.addTriangle( new SimpleVector( pointA.x, pointA.y - offset, pointA.z ), 0, 0,
	                     new SimpleVector( pointA.x, pointA.y + offset, pointA.z ), 0, 1,
	                     new SimpleVector( pointB.x, pointB.y + offset, pointB.z ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );
	    line.addTriangle( new SimpleVector( pointB.x, pointB.y + offset, pointB.z ), 0, 0,
	                     new SimpleVector( pointB.x, pointB.y - offset, pointB.z ), 0, 1,
	                     new SimpleVector( pointA.x, pointA.y - offset, pointA.z ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );
	    // Quad A, back-face:
	    line.addTriangle( new SimpleVector( pointB.x, pointB.y - offset, pointB.z ), 0, 0,
	                     new SimpleVector( pointB.x, pointB.y + offset, pointB.z ), 0, 1,
	                     new SimpleVector( pointA.x, pointA.y + offset, pointA.z ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );
	    line.addTriangle( new SimpleVector( pointA.x, pointA.y + offset, pointA.z ), 0, 0,
	                     new SimpleVector( pointA.x, pointA.y - offset, pointA.z ), 0, 1,
	                     new SimpleVector( pointB.x, pointB.y - offset, pointB.z ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );
	    // Quad B:
	    line.addTriangle( new SimpleVector( pointA.x, pointA.y, pointA.z + offset ), 0, 0,
	                     new SimpleVector( pointA.x, pointA.y, pointA.z - offset ), 0, 1,
	                     new SimpleVector( pointB.x, pointB.y, pointB.z - offset ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );
	    line.addTriangle( new SimpleVector( pointB.x, pointB.y, pointB.z - offset ), 0, 0,
	                     new SimpleVector( pointB.x, pointB.y, pointB.z + offset ), 0, 1,
	                     new SimpleVector( pointA.x, pointA.y, pointA.z + offset ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );
	    // Quad B, back-face:
	    line.addTriangle( new SimpleVector( pointB.x, pointB.y, pointB.z + offset ), 0, 0,
	                     new SimpleVector( pointB.x, pointB.y, pointB.z - offset ), 0, 1,
	                     new SimpleVector( pointA.x, pointA.y, pointA.z - offset ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );
	    line.addTriangle( new SimpleVector( pointA.x, pointA.y, pointA.z - offset ), 0, 0,
	                     new SimpleVector( pointA.x, pointA.y, pointA.z + offset ), 0, 1,
	                     new SimpleVector( pointB.x, pointB.y, pointB.z + offset ), 1, 1,
	                     TextureManager.getInstance().getTextureID( "texture8" ) );

	    // If you don't want the line to react to lighting:
	    //line.setLighting( Object3D.LIGHTING_NO_LIGHTS );
	   // line.setAdditionalColor(RGBColor.RED);
	    line.build();

	    // done
	    return line;
	}
	
	public Object3D getModel() {
		return model;
	}
	}
